<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //对象数组去重
      function isObject(val) {
        return typeof val == 'object' && val !== null
      }
      //判断两个对象是否相等
      function equal(val1, val2) {
        if (!isObject(val1) || !isObject(val2)) return val1 === val2
        if (val1 === val2) return true
        //如果是对象
        const val1Keys = Object.keys(val1)
        const val2Keys = Object.keys(val2)
        if (val1Keys.length !== val2Keys.length) return false
        //递归判断属性值是否相同
        for (const key of val1Keys) {
          if (!equal(val1[key], val2[key])) return false
        }
        //全部一样返回true
        return true
      }

      let obj1 = {
        a: 1,
        b: 3,
        c: {
          d: 1,
          f: 1
        }
      }
      let obj2 = {
        a: 1,
        b: 3,
        c: {
          d: 1,
          f: 1
        }
      }

      let objArr = [1, 2, obj1, obj2]

      function arrayRemove(arr) {
        const newArr = [...arr]
        for (let i = 0; i < newArr.length; i++) {
          for (let j = i + 1; j < newArr.length; j++) {
            if (equal(newArr[i], newArr[j])) {
              newArr.splice(j, 1)
            }
          }
        }
        return newArr
      }
      console.log(arrayRemove(objArr))
    </script>
  </body>
</html>
